package com.org.gen.service.impl;

import com.org.gen.entity.GenDatasourceConfig;
import com.org.gen.config.DbType;
import com.org.gen.mapper.GenDatasourceConfigMapper;
import com.org.gen.service.IGenDatasourceConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GenDatasourceConfigServiceImpl implements IGenDatasourceConfigService {

    @Autowired
    private GenDatasourceConfigMapper datasourceConfigMapper;

    public GenDatasourceConfig getById(int id) {
        return datasourceConfigMapper.getById(id);
    }

    public List<GenDatasourceConfig> listAll() {
        return datasourceConfigMapper.listAll();
    }

    public void insert(GenDatasourceConfig templateConfig) {
        templateConfig.setIsDeleted(0);
        DbType dbType = DbType.of(templateConfig.getDbType());
        if (dbType != null) {
            templateConfig.setDriverClass(dbType.getDriverClass());
        }
        datasourceConfigMapper.insert(templateConfig);
    }

    public void update(GenDatasourceConfig templateConfig) {
        datasourceConfigMapper.update(templateConfig);
    }

    public void delete(GenDatasourceConfig templateConfig) {
        datasourceConfigMapper.delete(templateConfig);
    }
}
